﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.IO.IsolatedStorage;
using Coding4Fun.Phone.Controls;

namespace NoiseMap
{
    public partial class Settings : PhoneApplicationPage
    {
        public Settings()
        {
            InitializeComponent();

            if (!IsolatedStorageSettings.ApplicationSettings.Contains("EnableLocation"))
            {
                EnableLocation.IsChecked = true;
            }
            else
            {
                EnableLocation.IsChecked = (bool?)IsolatedStorageSettings.ApplicationSettings["EnableLocation"] ?? true;
            }

            EnableLocation.Content = EnableLocation.IsChecked.Value ? AppResource.StartUsingLocationInfo : AppResource.StopUsingLocationInfo;
        }

        private void EnableLocation_Checked(object sender, RoutedEventArgs e)
        {
            IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = true;
            EnableLocation.Content = AppResource.StartUsingLocationInfo;
        }

        private void EnableLocation_Unchecked(object sender, RoutedEventArgs e)
        {
            IsolatedStorageSettings.ApplicationSettings["EnableLocation"] = false;
            EnableLocation.Content = AppResource.StopUsingLocationInfo;
        }

        private void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            new EmailComposeTask
            {
                Subject = AppResource.UsingLocationPrivaceDeclaration,
                Body = "",
                To = "baipengfei@gmail.com"
            }.Show();
        }

        private void Privacy_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MessagePrompt mp = new MessagePrompt
            {
                BorderThickness = new Thickness(0, 0, 0, 0),
                Title = AppResource.UsingLocationPrivaceDeclaration
            };


            var body = new Grid();
            body.Children.Add(new TextBlock
            {
                Text = AppResource.LocationServicePrivaceContent,
                TextWrapping = TextWrapping.Wrap
            });

            mp.Body = body;
            var btnComplete = new Button { Content = AppResource.ButtonOK };
            btnComplete.Click += (o, args) =>
            {
                mp.Hide();
            };

            mp.Show();
        }
    }
}